#include <iostream>
#include <limits>
#include <string>
using namespace std;
    
// 输入流的状态检查判断函数
void check_stream_status(){
    cout << "cin.goodbit() = " << cin.good() << endl;
    cout << "cin.badbit() = " << cin.bad() << endl;
    cout << "cin.eofbit() = " << cin.eof() << endl;
    cout << "cin.failbit() = " << cin.fail() << endl;
}

void test(){
    check_stream_status();
    int number;
    while(1){
        cout << "请输入一个数字" << endl;
        cin >> number;
        if(cin.bad() || cin.eof()){
            cout << "当前流已经结束" << endl;
        }else if(cin.fail()){
            
            //清空缓冲区
            cin.clear();
            //忽略内存空间内的多少个字节，到'\n'为止
            cin.ignore(1024,'\n');
            cout << "录入错误，请输入下一个数字" << endl;
        }else{
            //good()
            cout << "number=" << number << endl;
        }
    }
}   
    
int main(int atgc, char * argv[])
{   
    test();
    return 0;
}   
    
